package com.lianwei.hospital.Service.Impl;

import com.lianwei.hospital.Service.BookingInfoService;
import com.lianwei.hospital.mapper.BookingInfoMapper;
import com.lianwei.hospital.module.entity.BookingInfo;
import com.lianwei.hospital.module.entity.UserInfo;
import com.lianwei.hospital.module.vo.BookingVO;
import com.lianwei.hospital.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.print.Book;
import java.util.List;

@Service("BookingInfoService")
public class BookingInfoImpl implements BookingInfoService {
    @Autowired
    BookingInfoMapper bookingInfoMapper;

    @Override
    public BookingInfo selectByPrimaryKey(String uId) throws Exception {
        return bookingInfoMapper.selectByPrimaryKey(uId);
    }

    @Override
    public boolean insert(BookingInfo bookingInfo) throws Exception {
        return bookingInfoMapper.insert(bookingInfo)>0;
    }

    @Override
    public List<BookingInfo> selectAll() throws Exception {
        return bookingInfoMapper.selectAll();
    }

//    @Override
//    public boolean deleteByPrimaryKey(String uId) {
//        return bookingInfoMapper.deleteByPrimaryKey(uId)>0;
//    }


    @Override
    public boolean updateByPrimaryKey(BookingInfo bookingInfo) throws Exception {
        return bookingInfoMapper.updateByPrimaryKey(bookingInfo)>0;
    }

    @Override
    public PageUtil<BookingInfo> findPage(BookingVO query) throws Exception {
        /*
         * 1.获取总记录数
         * 2.如果总记录数 > 0 查询数据
         *  将数据封装到PageUtil
         * 否则，返回null
         */
        int count=bookingInfoMapper.countBySelectActive(query);
        if (count>0){
            List<BookingInfo> data=bookingInfoMapper.selectListBySelectActive(query);
            return new PageUtil<>(query.getCurrentPage(),query.getPageSize(),count,data);
        }
        return null;
    }
}
